const Router = require("koa-router");

const {
  userValidator,
  verifyUser,
  crpytPassword,
  verifyLogin,
} = require("../middleware/user.middleware");

const { auth, hadAdminPermission } = require("../middleware/auth.middleware");
const {
  register,
  login,
  changePassword,
  findAll,
  getUser,
  updateUser,
  findUserById,
  delUser,
  updatePassword,
  withdraw
} = require("../controller/user.controller");

const router = new Router({ prefix: "/users" });
// 提现
router.post("/withdraw", auth, withdraw);
//通过token 获取用户信息
router.get("/", auth, getUser);
//修改用户密码
router.put("/changePassword", auth, updatePassword);
// 删除用户
router.del("/:id", auth, delUser);
// 修改用户信息
router.put("/update", auth, crpytPassword, updateUser);

// 注册接口
router.post("/register", userValidator, verifyUser, crpytPassword, register);

// 登录接口
router.post("/login", userValidator, verifyLogin, login);

// 修改密码接口
router.put("/", auth, crpytPassword, changePassword);

// 用户列表
router.post("/list", auth, hadAdminPermission, findAll);
router.get("/:id", auth, findUserById);

module.exports = router;
